<?php

declare(strict_types=1);

namespace App\Listener\Admin;

use App\Constants\Admin\AdminLogCode;
use App\Event\Admin\Publics\AfterLogin as AdminAfterLogin;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use function Hyperf\Coroutine\co;

#[Listener]
class PublicsListener implements ListenerInterface
{
    public function __construct()
    {
    }

    /**
     * @return string[]
     */
    public function listen(): array
    {
        return [
            AdminAfterLogin::class
        ];
    }

    /**
     * @param object $event
     */
    public function process(object $event): void
    {
        if ($event instanceof AdminAfterLogin) {
            co(function () use ($event) {
                $event->admin->addLog(AdminLogCode::TYPE_LOGIN, '后台管理系统');
            });
        }
    }
}
